//
//  File.swift
//  Sina
//
//  Created by 周旭斌 on 2017/3/23.
//  Copyright © 2017年 周旭斌. All rights reserved.
//

import UIKit
import SVProgressHUD

let ScreenWidth : CGFloat = UIScreen.main.bounds.size.width;
let ScreenHeight: CGFloat = UIScreen.main.bounds.size.height;
let tabBarCount : Int = 5;
let ScreenBouds : CGRect = UIScreen.main.bounds;

// 机型判断
let IS_IPHONE4 : Bool = UIScreen.main.bounds.size.height == 480;
let IS_IPHONE5 : Bool = UIScreen.main.bounds.size.height == 568;
let IS_IPHONE6 : Bool = UIScreen.main.bounds.size.height == 667;
let IS_IPHONE6PLUS : Bool = UIScreen.main.bounds.size.height == 736;

/// 高度适配
func XBHeight(_ value : CGFloat) -> CGFloat {
    if IS_IPHONE4 {
        return 0.720 * value;
    }else if IS_IPHONE5 {
        return 0.852 * value;
    }else if IS_IPHONE6 {
        return 1.000 * value;
    }else {
        return 1.103 * value;
    }
}

/// 宽度适配
func XBWidth(_ value : CGFloat) -> CGFloat {
    if IS_IPHONE4 {
        return 0.853 * value;
    }else if IS_IPHONE5 {
        return 0.853 * value;
    }else if IS_IPHONE6 {
        return 1.000 * value;
    }else {
        return 1.104 * value;
    }
}

/// 统一网络get方法(逃逸闭包,在函数结束或者returen之后再执行,一般用于网络请求,异步返回的时候来执行)
func GET(_ URLString : String, parameters : Any?, progress : @escaping ((Progress) -> Void?), success : @escaping ((URLSessionDataTask, Any?) -> Void?), failure : @escaping((URLSessionDataTask? , Error) -> Void?)) {
    SVProgressHUD.show(withStatus: "正在加载...");
    XBNetWorkTool.shareInstance().get(URLString, parameters: parameters, progress: { (myProgress) in
        progress(myProgress);
    }, success: { (dataTask, responseData) in
        SVProgressHUD.dismiss();
        success(dataTask, responseData);
        
    }) { (dataTask, error) in
        SVProgressHUD.showError(withStatus: "网络繁忙,请稍后再试!");
        failure(dataTask, error);
    }
}

